#include "Stdafx.h"
#include "Executor.h"
#include "LuaFunctionEditer.h"

namespace BatchRename
{
	Executor::Executor(void)
	{
	}

	Executor::~Executor(void)
	{
	}

	bool Executor::Initialize()
	{
		const QVector<LuaFunction*>& luas = LuaFunctionRule::Single().ConstLuaFuncKey();
		foreach(LuaFunction* lua, luas)
		{
			lua->Reset();
		}
		return true;
	}

	QString Executor::ExecutorResult(QString nameRule, QString SuffixRule)
	{
		const QVector<LuaFunction*>& luas = LuaFunctionRule::Single().ConstLuaFuncKey();
		foreach(LuaFunction* lua, luas)
		{
			QString result = lua->Result();
			nameRule.replace(QRegExp("<" + lua->FuncTitle() + ">"), result);
			SuffixRule.replace(QRegExp("<" + lua->FuncTitle() + ">"), result);
		}
		return SuffixRule == "" ? nameRule : (nameRule + "." + SuffixRule);
	}

	bool Executor::Finishlize()
	{
		return true;
	}
}